<ui:composition template="/WEB-INF/templates/customer/base.xhtml"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets">

	<ui:define name="title">Dettagli Pacchetto</ui:define>

	<ui:define name="content">
		<h:form>
			<p:wizard id="tabView" flowListener="#{cartPackageBean.flowListener}">
				<p:tab id="dateTab" title="Date">
					<p:panel>
						<p:fragment autoUpdate="true">
							<h:panelGrid columns="3" columnClasses="label, value, message">
								<h:outputLabel value="Seleziona data di partenza:" for="date" />
								<p:calendar id="date" pattern="dd-MM-yyyy" mindate="new Date();" value="#{cartPackageBean.pack.date}" />
								<p:message for="date" />

								<h:outputLabel value="Seleziona numero notti:" for="duration" />
								<p:spinner min="1" id="duration" value="#{cartPackageBean.pack.duration}" />
								<p:message for="duration" />
							</h:panelGrid>
						</p:fragment>
					</p:panel>
				</p:tab>

				<p:tab id="goingTab" title="Andata">
					<p:panel>
						<p:fragment autoUpdate="true">
							<p:dataTable id="goingTable" var="transport"
								value="#{transportBean.getToDestination(cartPackageBean.pack.city)}" rows="10"
								paginator="true">
								<p:column headerText="Id">
									<h:outputText value="#{transport.id}" />
								</p:column>

								<p:column headerText="Nome">
									<h:outputText value="#{transport.name}" />
								</p:column>

								<p:column headerText="Origine">
									<h:outputText value="#{transport.origin}" />
								</p:column>

								<p:column headerText="Destinazione">
									<h:outputText value="#{transport.destination}" />
								</p:column>

								<p:column headerText="Prezzo">
									<h:outputText value="#{transport.price}" />
								</p:column>

								<p:column headerText="Seleziona">
									<p:commandButton rendered="#{cartPackageBean.pack.going.id != transport.id}"
										value="Seleziona" action="#{cartPackageBean.selectGoing(transport)}" />
									<h:outputText value="Selezionato"
										rendered="#{cartPackageBean.pack.going.id == transport.id}" />
								</p:column>
							</p:dataTable>
							<p:message for="goingTable" />
						</p:fragment>
					</p:panel>
				</p:tab>

				<p:tab id="backTab" title="Ritorno">
					<p:panel>
						<p:fragment autoUpdate="true">
							<p:dataTable id="backTable" var="transport"
								value="#{transportBean.getFromOrigin(cartPackageBean.pack.going.destination)}" rows="10"
								paginator="true">
								<p:column headerText="Id">
									<h:outputText value="#{transport.id}" />
								</p:column>

								<p:column headerText="Nome">
									<h:outputText value="#{transport.name}" />
								</p:column>

								<p:column headerText="Origine">
									<h:outputText value="#{transport.origin}" />
								</p:column>

								<p:column headerText="Destinazione">
									<h:outputText value="#{transport.destination}" />
								</p:column>

								<p:column headerText="Prezzo">
									<h:outputText value="#{transport.price}" />
								</p:column>

								<p:column headerText="Seleziona">
									<p:commandButton value="Seleziona" action="#{cartPackageBean.selectBack(transport)}"
										rendered="#{cartPackageBean.pack.back.id != transport.id}" />
									<h:outputText value="Selezionato"
										rendered="#{cartPackageBean.pack.back.id == transport.id}" />
								</p:column>
							</p:dataTable>
							<p:message for="backTable" />
						</p:fragment>
					</p:panel>
				</p:tab>

				<p:tab id="accomodationTab" title="Alloggio">
					<p:panel>
						<p:fragment autoUpdate="true">
							<p:dataTable id="accomodationTable" var="accomodation"
								value="#{accomodationBean.getFiltered(cartPackageBean.pack.city)}" rows="10"
								paginator="true">
								<p:column headerText="Id">
									<h:outputText value="#{accomodation.id}" />
								</p:column>

								<p:column headerText="Nome">
									<h:outputText value="#{accomodation.name}" />
								</p:column>

								<p:column headerText="Città">
									<h:outputText value="#{accomodation.city}" />
								</p:column>

								<p:column headerText="Prezzo">
									<h:outputText value="#{accomodation.price}" />
								</p:column>

								<p:column headerText="Seleziona">
									<p:commandButton value="Seleziona"
										action="#{cartPackageBean.selectAccomodation(accomodation)}"
										rendered="#{cartPackageBean.pack.accomodation.id != accomodation.id}" />
									<h:outputText value="Selezionato"
										rendered="#{cartPackageBean.pack.accomodation.id == accomodation.id}" />
								</p:column>
							</p:dataTable>
							<p:message for="accomodationTable" />
						</p:fragment>
					</p:panel>
				</p:tab>

				<p:tab id="activityTab" title="Attività">
					<p:panel>
						<p:fragment autoUpdate="true">
							<p:dataTable var="d" value="#{cartPackageBean.daysList}">
								<p:column>
									<h:outputLabel value="Attività Giorno #{d}:" />
								</p:column>
								<p:column>
									<p:commandButton value="Seleziona" actionListener="#{cartPackageBean.chooseActivity(d)}">
										<p:ajax event="dialogReturn" listener="#{cartPackageBean.selectActivity}" />
									</p:commandButton>
									<p:commandButton icon="ui-icon-close" action="#{cartPackageBean.pack.schedule.remove(d)}" rendered="#{cartPackageBean.pack.schedule.get(d) != null}"/>
								</p:column>
								<p:column>
									<h:outputText rendered="#{cartPackageBean.pack.schedule.get(d) != null}" value="Selezionato: #{cartPackageBean.pack.schedule.get(d).activity.name}" />
									<h:outputText rendered="#{cartPackageBean.pack.schedule.get(d) == null}" value="Non ancora selezionata" />
								</p:column>
							</p:dataTable>
						</p:fragment>
					</p:panel>
				</p:tab>

				<p:tab id="summaryTab" title="Riepilogo">
					<p:panel>
						<p:fragment autoUpdate="true">
							<p:panelGrid columns="3" columnClasses="label, value, message">
								<h:outputLabel value="Seleziona numero partecipanti:" for="quantity" />
								<p:spinner min="1" id="quantity" value="#{cartPackageBean.pack.quantity}">
									<p:ajax event="change" />
								</p:spinner>
								<h:message for="quantity" />
							</p:panelGrid>

							<p:panelGrid id="total" columns="3">
								<h:outputText value="Totale:" />
								<h:outputText value="#{cartPackageBean.pack.price} x #{cartPackageBean.pack.quantity}" />
								<h:outputText value="= #{cartPackageBean.pack.price * cartPackageBean.pack.quantity} €" />
							</p:panelGrid>
							
							<p:commandButton value="Aggiungi a Carrello" action="#{cartPackageBean.addToCart}" />
							<p:commandButton value="Aggiungi a Giftlist" action="#{cartPackageBean.addToGiftlist}" />
							<h:link value="Condividi" outcome="#{cartPackageBean.url}"/>
						</p:fragment>
					</p:panel>
				</p:tab>
			</p:wizard>
		</h:form>
	</ui:define>
</ui:composition>